package com.dongdongshop.service.impl;

import com.dongdongshop.data.PageBean;
import com.dongdongshop.mapper.TbContentCategoryMapper;
import com.dongdongshop.mapper.TbContentMapper;
import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.service.ContentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class ContentServiceImpl implements ContentService {

    @Autowired
    private TbContentMapper tbContentMapper;

    @Autowired
    private TbContentCategoryMapper tbContentCategoryMapper;

    @Override
    public List<TbContentCategory> getContentCateGory(String name) {

        return tbContentCategoryMapper.getContentCateGory(name);
    }

    @Override
    public void insertContent(TbContentCategory contentCategory) {

        tbContentCategoryMapper.insertSelective(contentCategory);
    }

    @Override
    public TbContentCategory getContent(Long id) {

        return tbContentCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateContent(TbContentCategory tbContentCategory) {

        tbContentCategoryMapper.updateByPrimaryKeySelective(tbContentCategory);
    }

    @Override
    public void deleteContent(Long[] id) {

        tbContentCategoryMapper.deleteContent(id);
    }

    @Override
    public PageBean<TbContent> getContentList(Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<TbContent> list = tbContentMapper.getContentList();
        PageInfo<TbContent> info = new PageInfo<>(list);
        return new PageBean<TbContent>(info.getPageNum(), info.getPageSize(), info.getTotal(), info.getPages(), info.getList());
    }

    @Override
    public List<TbContentCategory> selectContentList() {

        return tbContentCategoryMapper.selectByExample(null);
    }

    @Override
    public void insertContents(TbContent content) {
        tbContentMapper.insertSelective(content);
    }

    @Override
    public TbContent getContentById(Long id) {

        return tbContentMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateContents(TbContent content) {

        tbContentMapper.updateByPrimaryKeySelective(content);
    }

    @Override
    public List<TbContent> getBannerImg(Long categoryId,Integer pageSize,Integer end) {

        return tbContentMapper.getBannerImg(categoryId,pageSize,end);
    }
}
